<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    let arr = ['赵云', '黄忠', '关羽', '张飞', '马超', '刘备', '曹操']
    // 这里要取的随机数是数组的索引,也就是0~length-1,写成Math.floor(Math.random() * (length-1+1))
    //                                            简写成Math.floor(Math.random() * (length)
    let i = Math.floor(Math.random() * arr.length)
    document.write(arr[i])
  </script>
</body>

</html>